import http from "../http/index";

console.log(http)
let Login = {
    namespaced: true,
    state: {
        isLogin: false,
        vip: [],
        username: '',
        password: ''
    },
    mutations: {
        login(state: any) {
            state.isLogin = true
        },
        admin(state: any, layout: any) {
            layout.forEach((item: object) => {
                state.vip.push(item)
            })
        },
        vip(state: any, layout: any) {
            layout.forEach((item: object) => {
                state.vip.push(item)
            })
        },
        get(state: any) {
            console.log(state.vip)
        },
        setUser(state: any, payload: any) {
            state.username = payload.username
            state.password = payload.password
        }
    },
    actions: {
        async getTeacher(context: any) {
            let user = await http.get('/user');
            console.log(user.data.teacher)
            context.commit('setUser', user.data.teacher)
        },
        async getAdmin(context: any) {
            let user = await http.get('/user');
            console.log(user.data.student)
            context.commit('setUser', user.data.student)
        }
    }
    ,
    getters: {
        indexLength(state: any) {
            console.log(state.vip.length)
            return state.vip.length
        }
    }
}
export default Login